package com.liuzy.crawler.core;

import com.liuzy.crawler.Config;
import com.liuzy.crawler.pool.CachePool;
import com.liuzy.crawler.pool.DownLoadPool;
import com.liuzy.crawler.pool.ScannerPool;

/**
 * @author liuzy
 * @since 2015年9月17日
 */
public class Crawler {

	public static DownLoadPool downLoadPool;
	public static CachePool cachePool;
	public static ScannerPool scannerPool;

	private static volatile boolean isRun;

	public static void startup(String[] urls) {
		isRun = true;

		downLoadPool = new DownLoadPool(Config.dlDir, Config.dlSize, Config.dlcount);
		downLoadPool.startup();

		scannerPool = new ScannerPool(Config.scanSize, Config.scanCount);
		scannerPool.startup();

		cachePool = new CachePool(Config.cacheDir, Config.cacheSize, Config.cacheCount);
		cachePool.startup();

		for (String url : urls) {
			cachePool.add(url);
		}

	}

	public static boolean shutdown() {
		if (isRun) {
			isRun = false;
			scannerPool.shutdown();
			downLoadPool.shutdown();
			cachePool.shutdown();
			saveConfig();
		}
		return true;
	}

	public static boolean isRun() {
		return isRun;
	}

	public static void saveConfig() {

	}

}
